import { axios } from '@/service/service'
import utils from '@/utils'


export function queryTaskInstancesReq(params: any): any {
  return axios({
    url: '/api-scheduler/taskInstance/queryTaskInstances',
    method: 'get',
    params
  })
}

export function stopTmpTaskReq(params: any): any {
  return axios({
    url: '/api-scheduler/executors/execute',
    method: 'get',
    params
  })
}

export function queryLogReq(params: any): any {
  return axios({
    url: '/api-scheduler/log/detail',
    method: 'get',
    params
  })
}

export function queryTaskListPaging(
  params: any,
  projectCode: any
): any {
  return axios({
    url: `/projects/${projectCode.projectCode}/task-instances`,
    method: 'get',
    params
  })
}

export function forceSuccess(taskId: any, projectCode: any): any {
  return axios({
    url: `/projects/${projectCode.projectCode}/task-instances/${taskId.id}/force-success`,
    method: 'post'
  })
}

export function downloadLog(id: number): void {
  utils.downloadFile('log/download-log', { taskInstanceId: id })
}

export function streamTaskStop(projectCode: number, taskId: number): any {
  return axios({
    url: `projects/${projectCode}/task-instances/${taskId}/stop`,
    method: 'post'
  })
}

export function savePoint(projectCode: number, taskId: number): any {
  return axios({
    url: `projects/${projectCode}/task-instances/${taskId}/savepoint`,
    method: 'post'
  })
}

